﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 10/04/2009
// Time: 19:49
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of ProductSubGroup.
	/// </summary>	
	public class ProductSubGroup : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _name;
			private string _group_id;
		#endregion
		
		#region properties
		public string name 
		{
			get { return _name; }
			set { _name = value; }
		}
		
		public string GroupId 
		{
			get { return _group_id; }
			set { _group_id = value; }
		}
			
		#endregion
		
		public ProductSubGroup()
		{
			gsql.table = "common.product_sub_group";
			_sequence  = "common.product_sub_group_product_sub_group_id_seq";
		}
		
		public void clear()
		{
			_id   = string.Empty;
			_name = string.Empty;
			_group_id = string.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id = dr["product_sub_group_id"].ToString();
			_name = dr["product_sub_group_name"].ToString();
			_group_id = dr["product_sub_group_group_id"].ToString();
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id, "product_sub_group_id");
			gsql.setValue(_name, "product_sub_group_name");
			gsql.setValue(_group_id, "product_sub_group_group_id");
		}	
	}
    
	public class ProductSubGroups : common.DefaultList, common.IList
	{
		public ProductSubGroups()
		{
			gsql.table = "common.product_sub_group";
		}
				
		/*public List<ProductSubGroup> items
		{
			get { return items; }
		}*/
		
		public ProductSubGroup get(Int32 index)
		{
			return (ProductSubGroup)items[index];
		}
		
		public ProductSubGroup get()
		{
			return (ProductSubGroup)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.additionalWhere = "ORDER BY product_sub_group_name";
			
			return mountList();
		}
		
		public bool fillListByGroup(String idGroup)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "product_sub_group_group_id = '"+idGroup+"'";
			gsql.additionalWhere = "ORDER BY product_sub_group_name";
				
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				ProductSubGroup t = new ProductSubGroup();
				t.get(gsql.getRow(i));
				items.Add(t);
			}
			return true;
		}
	}    	
}
